#include <iostream>
using namespace std;
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>

int main()
{
	int ones[] = { 1, 2, 3, 4, 5 };
	int twos[] = { 10,20,30,40,50 };
	int result[5];
	transform(ones, ones + 5, twos, result, std::plus<int>());
	for_each(result, result + 5, [](int a)->void {cout << a << endl; }); // Lambda表达式(匿名函数)
	cout << endl;

	// find
	int arr[] = { 0,1,2,3,4,5,6,7,7,7,8 };
	int len = sizeof(arr) / sizeof(arr[0]);

	cout << count(arr, arr + len, 7) << endl; // 元素7的个数
	cout << endl;

	// cout << count_if(arr, arr + sizeof(arr) / sizeof(arr[0]), bind2nd(less<int>(), 7)) << endl; // 小于7的个数
	cout << count_if(arr, arr + len, [](int a)-> bool {return a < 7; }) << endl; // 小于7的个数
	cout << endl;

	// 二分查找
	cout << binary_search(arr, arr + len, 9) << endl; // 9找不到

	vector<int> iA(arr + 2, arr + 6);
	cout << *search(arr, arr + len, iA.begin(), iA.end()) << endl;
	return 0;
}
